<?php
		function serializeTo($fName='dump/data.json',$data=array()){
			if(is_readable($fName)){
				unlink($fName);
			}
			$fp = fopen($fName, "a");
			if($fp){
				fwrite($fp, json_encode($data));
				fclose($fp);
			}
		}
		
		function deSerializeFrom($fName='dump/data.json'){
			if(is_readable($fName)){
				return json_decode(file_get_contents($fName));
			}else{
				return false;
			}
		}
		if(isset($_SESSION['user'])){
			$data['run']=true;
			$data['interval']=5;
			$maxQty=5;
			serializeTo("dump/cron.json",$data);
			$startTime = time();
			$numb=0;
			function get_run(){
				$d = deSerializeFrom("dump/cron.json");
				return $d->run;
			}
			function get_interval(){
				$d = deSerializeFrom("dump/cron.json");
				return $d->interval;
			}
			while((get_run())==true){
				sleep(get_interval());
				if($numb>$maxQty){
					$numb=0;
					$ds=scandir(site_path.'dump');
					for($i=2;$i<count($ds);$i++){
					$d=site_path.'dump'.DIRSEP.$ds[$i];
					if( is_file( $d )&&ereg("mgucomua_conference", $d)){   
						$j = explode("_", $d);                             
						if(isset($j)&&count($j)==2){                       
							$time = intval(($j[1]));                       
							//if($time+60<time());                         
						}                                                  
						unlink($d);                                    
					}                                                      
					}
				}
				if(get_run()){
					include 'engine/db_dump.php';
					$numb++;
				}
			}
			echo $numb;
		}
?>